﻿#include "massview.h"
#include "ui_massview.h"

MassView::MassView(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::MassView)
{
    ui->setupUi(this);

    model=new QSqlQueryModel(this);

    ui->tableView->setModel(model);
    ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
}

MassView::~MassView()
{
    delete ui;
}

void MassView::setHeaderData()
{
    model->setHeaderData(0,Qt::Horizontal,QStringLiteral("日期"));
    model->setHeaderData(1,Qt::Horizontal,QStringLiteral("单号"));
    model->setHeaderData(2,Qt::Horizontal,QStringLiteral("质量"));
}

void MassView::on_btn_today_clicked()
{
    QSqlQuery query(QString("select date,number,mass from td_mass where date = '%1'").arg(Env::date));
    model->setQuery(query);

    setHeaderData();
}

void MassView::on_btn_month_clicked()
{
    QString preDate=Env::month + "-01";
    QString postDate=Env::month + "-31";

    QString sql="select date,number,mass from td_mass where date >= '%1' and date <= '%2'";
    QSqlQuery query(sql.arg(preDate).arg(postDate));

    model->setQuery(query);

    setHeaderData();
}
